/*
 * MapEditorMain.java
 *
 * Created on Ponedeljek, 12 maj 2008, 22:14
 */

package ipark.gui.mapeditor;

import java.awt.GridLayout;
import java.awt.Rectangle;
import java.beans.PropertyVetoException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JInternalFrame;
import java.util.*;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import java.awt.event.*;
import javax.swing.DefaultCellEditor;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;
import javax.swing.event.*;
import javax.swing.table.TableModel;
import javax.swing.table.TableCellEditor;
import org.jgrapht.graph.*;


/**
 * GUI class for map editor
 * @author  jernej
 */
public class MapEditorMain extends javax.swing.JFrame {

    private Vector<JInternalFrame> seznamOken = new Vector<JInternalFrame>();
    private Vector<WorkArea> seznamArea = new Vector<WorkArea>();
    private Vector<JMenuItem> seznamMeni = new Vector<JMenuItem>();
    private ComponentEvent propertyListener;
    private Vector<MapComponent> seznamKomponent = new Vector<MapComponent>();
    private boolean isPassageAdded = false;
    private int activeArea = -1;
    private int mostUpper = -1;
    private int mostLower = 0;
    private MapControl controlObj = new MapControl();
    
    private final int FLOOR_UPPER = 1;
    private final int FLOOR_LOWER = 0;
    private final int FLOOR_ASK = -1;
    
    
    /** Creates new form MapEditorMain */
    public MapEditorMain() {
        initComponents();
        //okno odpremo čez cel zaslon
        setExtendedState(getExtendedState() | MAXIMIZED_BOTH);
        //dodamo komponente na toolbar
        jPanel3.setLayout(new GridLayout(6,2));
        addToolBar(CrossRoad.class, 50, 50);
        addToolBar(ParkingBox.class, 40, 55);
        addToolBar(Road.class, 40, 50);
        addToolBar(Turn.class, 40, 40);
        addToolBar(Passage.class,40,55);
        addToolBar(Entrance.class, 40,20);
        addToolBar(Exit.class, 40,40);
        addToolBar(Gateway.class, 40, 20);
        addToolBar(Sensor.class, 35, 35);
        addToolBar(Camera.class, 35, 35);
        addToolBar(Wall.class,50,10);
        configurePropertyEditor();
        // poskusimo prebrati mapo iz datoteke
        Vector<WorkArea> readData = null;
        try
        {
          readData = controlObj.loadMapFromFile();
        }
        catch(Exception ex)
        {
          //drugače odpremo novo okno
          SwingUtilities.invokeLater(new Runnable() {
            public void run() {
               addWindow(FLOOR_UPPER);
            }
          });
        }
        if(readData!=null){
            //če nam je uspelo prebrati mapo, jo prikažemo in nastavimo potrebne lastnosti
            for(int i=0;i<readData.size();i++){
                readData.get(i).setListeners();
                if(readData.get(i).getFloorNumber()<mostLower)
                    mostLower = readData.get(i).getFloorNumber();
                if(readData.get(i).getFloorNumber()>mostUpper)
                    mostUpper = readData.get(i).getFloorNumber();
                addWindow(readData.get(i));
                Vector<MapComponent> flItems = readData.get(i).getAllComponents();
                for(int j=0;j<flItems.size();j++)
                    flItems.get(j).loadImages();
            }
        }
        //bugfix - če ne bi bilo tega, začetno okno ne bi imelo fokusa
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                try {
                    seznamOken.get(0).setSelected(true);
                } catch (PropertyVetoException ex) {
                    Logger.getLogger(MapEditorMain.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }

    /** 
     * add listener for component changes
     */
    private void configurePropertyEditor() {
        //pripravimo class, ki po poslušal za spremembe na komponentah
        propertyListener = new ComponentEvent() {
            //dogodek, ko se komponenti spremeni lastnost
            @Override
            public void propertyChanged(MapComponent comp) {
                if(jComboBox1.getSelectedItem().equals(comp.getName()))
                    fillProperties(comp);
            }
            //dogodek, ki se proži ob novi komponenti
            @Override
            public void componentAdded(MapComponent comp) {
                jComboBox1.addItem(comp.getName());
                jComboBox1.setSelectedItem(comp.getName());
                seznamKomponent.add(comp);
                jTable1.setEnabled(true);
                if(comp instanceof Passage){
                    isPassageAdded = true;
                    for(int i=0;i<seznamArea.size();i++)
                        if(i!=activeArea)
                            seznamArea.get(i).addMapComponent(comp.duplicate());
                }
            }
            //proži se ob tem, ko je izbrana ena ali več komponent
            public void componentSelected(Vector<MapComponent> components){
                if(components.size()>1){
                    jTable1.setEnabled(false);
                } else {
                    jComboBox1.setSelectedItem(components.get(0).getName());
                    fillProperties(components.get(0));
                    jTable1.setEnabled(true);
                }
            }
            //proži se, ko je kompnenta odstranjena
            public void componentRemoved(MapComponent component){
                jComboBox1.removeItem(component.getName());
                seznamKomponent.remove(component);
                if(seznamKomponent.size()==0)
                    jTable1.setModel(new javax.swing.table.DefaultTableModel());
            }
        };
    }
    
    /**
     * Add specific component to the toolbar
     * @param clName        Class of component
     * @param iconWidth     icon width
     * @param iconHeight    icon height
     */
    private void addToolBar(final Class clName,int iconWidth, int iconHeight){
        MapComponent newComp = null;
        //kreiramo novo komponento
        try {
            newComp = (MapComponent) clName.newInstance();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        //ustvarimo napis in sliko, ki bo označeval novo komponento
        JLabel component = new JLabel(newComp.getName(),newComp.getIcon(iconWidth,iconHeight),JLabel.CENTER);
        component.setVerticalTextPosition(JLabel.BOTTOM);
        component.setHorizontalTextPosition(JLabel.CENTER);
        component.addMouseListener(new java.awt.event.MouseAdapter() {
                @Override
                // ob pritisku na to sliko, bomo dodali novo komponento
                public void mousePressed(MouseEvent e) {
                    MapComponent newComp = null;
                    try {
                        newComp = (MapComponent) clName.newInstance();
                    } catch (Exception ex) {
                        Logger.getLogger(MapEditorMain.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    seznamArea.get(activeArea).addMapComponentFloating(newComp);
                }
            });
        //dodamo komponento na toolbar
        jPanel3.add(component);
    }
    
    /**
     * add new window
     * @param area  area, which will be in window
     */
    private void addWindow(final WorkArea area){
        //generiramo ime okna
        String imeOkna = "Floor " + Integer.toString(area.getFloorNumber());
        //generiramo okno
        JInternalFrame okno = new JInternalFrame(imeOkna,true,true,true);
        okno.setDefaultCloseOperation(JInternalFrame.HIDE_ON_CLOSE);
        okno.setBounds(0, 0, 500,500);
        okno.setVisible(true);
        //dodamo scroll bar
        JScrollPane scrollPane = new JScrollPane(area,
        JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
        JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        okno.getContentPane().add(scrollPane);
        okno.pack();
        //dodamo okno in delovno površino na seznam obstoječih
        seznamOken.add(okno);
        seznamArea.add(area);
        //prikažemo vse komponente v property editorju
        jComboBox1.removeAllItems();
        if(isPassageAdded){
            Vector<MapComponent> listElem = seznamArea.get(0).getAllComponents();
            for(int i=0;i<listElem.size();i++)
                if(listElem.get(i) instanceof Passage)
                    area.addMapComponent(listElem.get(i).duplicate());
        }
        JMenuItem oknoItem = new JMenuItem(imeOkna);
        //ko izberemo postavko v meniju, ta prikaže ustrezno okno v ospredju
        oknoItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                int indexArea = seznamArea.indexOf(area);
                seznamOken.get(indexArea).toFront();
                seznamOken.get(indexArea).setVisible(true);
                try {
                    seznamOken.get(indexArea).setSelected(true);
                } catch (PropertyVetoException ex) {}
            }
        });
        okna.add(oknoItem);
        //dodamo še meni na seznam
        seznamMeni.add(oknoItem);
        //ustvarimo listener, ki bo skrbel, da se osveži property editor, ko bo okno aktivirano
        okno.addInternalFrameListener(new InternalFrameAdapter() {
            @Override
            public void internalFrameActivated(InternalFrameEvent e) {
                int indexArea = seznamArea.indexOf(area);
                if(activeArea>-1)
                    seznamArea.get(activeArea).removeComponentListener(propertyListener);
                seznamArea.get(indexArea).addComponentListener(propertyListener);
                activeArea = indexArea;
                jComboBox1.removeAllItems();
                seznamKomponent.clear();
                seznamKomponent.addAll(seznamArea.get(indexArea).getAllComponents());
                seznamArea.get(indexArea).clearSelection();
                for(int i=0;i<seznamKomponent.size();i++)
                    jComboBox1.addItem(seznamKomponent.get(i).getName());
                if(seznamKomponent.size()>0){
                    jComboBox1.setSelectedIndex(0);
                    fillProperties(seznamKomponent.get(0));
                } else
                    jTable1.setModel(new javax.swing.table.DefaultTableModel());
            }
        });
        //dodamo okna na container, ki vsebuje še ostala
        windowManager.add(okno,javax.swing.JLayeredPane.DEFAULT_LAYER);
        //okno maksimiziramo in ga naredimo trenutno aktivnega
        try {
            okno.setMaximum(true);
            okno.setSelected(true);
            activeArea = seznamArea.indexOf(area);
        } catch (java.beans.PropertyVetoException e) {}
    }
    
    /**
     * add new floor
     * @param typeFloor which floor do we want to add (upper, lower, ask)
     */
    private void addWindow(int typeFloor){
        // glede na podan tip ustvarimo okno, ki se lahko nahaja pod ali nad obstoječimi
        int fType = typeFloor;
        int flNum = 0;
        //lahko tudi vprašamo uporabnika kaj želi dodati
        if(fType==FLOOR_ASK){
            Object[] options = {"Upper floor","Lower floor","Cancel"};
            fType = JOptionPane.showOptionDialog(this,"Which floor do you want to add?",
            "Add floor...",JOptionPane.YES_NO_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE,
            null,options,options[2]);
        }
        if(fType==2) return;
        if(mostUpper<mostLower){
            flNum = 0;
            mostUpper = 0;
        } else
            switch(fType){
                case 0:
                    mostUpper++;
                    flNum = mostUpper;
                break;
                case 1:
                    mostLower--;
                    flNum = mostLower;
                break;
            }
        //kličemo funkcijo, ki dokonča dodajanje oken
        WorkArea area = new WorkArea(flNum);
        area.setListeners();
        addWindow(area);
    }
    
    /**
     * read component properties and show them in property editor
     * @param get   component, which properties will be displayed
     */
    private void fillProperties(MapComponent get) {
        String[] properties = get.getPropertyNames();
        Object[][] podatki = new Object[properties.length][2];
        //preberemo obstoječe komponente
        for(int i=0;i<properties.length;i++){
            podatki[i][0] = properties[i];
            String[] typeNames = get.getTypeNames(properties[i]);
            //če je lastnost izbirnega tipa, ustvarimo spustni meni
            if(typeNames!=null){
                JComboBox combo = new JComboBox(typeNames){
                @Override
                    public String toString(){
                        return getSelectedItem().toString();
                    }
                };
                combo.setSelectedItem(get.getPropertyValue(properties[i]));
                podatki[i][1] = combo;
            }
            else
                podatki[i][1] = get.getPropertyValue(properties[i]);
        }
        //povemo tabeli, kateri podatki se lahko spreminjajo
        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            podatki, new String [] {"", ""}){
            @Override
            public boolean isCellEditable(int row,int column){
                if(column==1)
                    return true;
                else
                    return false;
            }
        });
        jTable1.getModel().addTableModelListener(new TableModelListener() {
            //če pride do spremembe v property editorju, to obdelamo
            public void tableChanged(TableModelEvent e) {
                int row = e.getFirstRow();
                TableModel model = (TableModel)e.getSource();
                String data = (String)model.getValueAt(row, 1);
                String param = (String)model.getValueAt(row, 0);
                //če se spremeni ime, moramo preveriti, če je edinstveno
                if(param.equals("Name")){
                    for(int i=0;i<seznamKomponent.size();i++)
                        if(seznamKomponent.get(i).getName().equals(data)){
                            JOptionPane.showMessageDialog(null, "This name already exist!");
                            for(int j=0;j<seznamKomponent.size();j++)
                                if(seznamKomponent.get(j).getName().equals(jComboBox1.getSelectedItem()))
                                    fillProperties(seznamKomponent.get(j));
                            return;
                        }
                }
                //spremenimo lastnost
                for(int i=0;i<seznamKomponent.size();i++)
                    if(seznamKomponent.get(i).getName().equals(jComboBox1.getSelectedItem())){
                        if(!seznamKomponent.get(i).setPropertyValue(param,data)){
                            JOptionPane.showMessageDialog(null, "Property has NOT been changed!");
                        }
                        fillProperties(seznamKomponent.get(i));
                        break;
                    }
                //če se je spremenilo ime, to popravimo v spustnem meniju
                if(param.equals("Name")){
                    jComboBox1.removeAllItems();
                    for(int i=0;i<seznamKomponent.size();i++){
                        jComboBox1.addItem(seznamKomponent.get(i).getName());
                        if(seznamKomponent.get(i).getName().equals(data))
                            fillProperties(seznamKomponent.get(i));
                    }
                    jComboBox1.setSelectedItem(data);
                }
                seznamArea.get(activeArea).repaint();
            }
        });
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel4 = new javax.swing.JPanel();
        windowManager = new javax.swing.JDesktopPane();
        toolBar = new javax.swing.JToolBar();
        newWindow = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jSpinner1 = new javax.swing.JSpinner();
        jLabel1 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        jComboBox1 = new javax.swing.JComboBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable(){
            public TableCellEditor getCellEditor(int row, int column) {
                if (dataModel.getValueAt(row, 1) instanceof JComboBox ){
                    return new DefaultCellEditor((JComboBox)dataModel.getValueAt(row, column));
                }
                else
                return super.getCellEditor(row,column);
            }
        };
        meni = new javax.swing.JMenuBar();
        datoteka = new javax.swing.JMenu();
        jMenuItem4 = new javax.swing.JMenuItem();
        jMenuItem5 = new javax.swing.JMenuItem();
        zapri = new javax.swing.JMenuItem();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenuItem1 = new javax.swing.JMenuItem();
        okna = new javax.swing.JMenu();
        novoOkno = new javax.swing.JMenuItem();
        zapriOkno = new javax.swing.JMenuItem();
        separator = new javax.swing.JSeparator();

        jPanel4.setName("jPanel4"); // NOI18N

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(ipark.IParkApp.class).getContext().getResourceMap(MapEditorMain.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setName("Form"); // NOI18N

        windowManager.setName("windowManager"); // NOI18N

        toolBar.setFloatable(false);
        toolBar.setRollover(true);
        toolBar.setName("toolBar"); // NOI18N

        newWindow.setText(resourceMap.getString("newWindow.text")); // NOI18N
        newWindow.setFocusable(false);
        newWindow.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        newWindow.setName("newWindow"); // NOI18N
        newWindow.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        newWindow.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newWindowActionPerformed(evt);
            }
        });
        toolBar.add(newWindow);

        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        toolBar.add(jButton1);

        jPanel1.setName("jPanel1"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jSpinner1.setModel(new javax.swing.SpinnerNumberModel(0.04d, 0.01d, 0.5d, 0.01d));
        jSpinner1.setDoubleBuffered(true);
        jSpinner1.setName("jSpinner1"); // NOI18N
        jSpinner1.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jSpinner1StateChanged(evt);
            }
        });

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(447, Short.MAX_VALUE)
                .addComponent(jLabel2)
                .addGap(2, 2, 2)
                .addComponent(jSpinner1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(3, 3, 3)
                .addComponent(jLabel1)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jSpinner1, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        toolBar.add(jPanel1);

        jPanel3.setName("jPanel3"); // NOI18N

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 219, Short.MAX_VALUE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 143, Short.MAX_VALUE)
        );

        jPanel5.setName("jPanel5"); // NOI18N

        jComboBox1.setName("jComboBox1"); // NOI18N
        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jTable1.setName("jTable1"); // NOI18N
        jScrollPane1.setViewportView(jTable1);

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jComboBox1, javax.swing.GroupLayout.Alignment.TRAILING, 0, 219, Short.MAX_VALUE)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 219, Short.MAX_VALUE)
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE))
        );

        meni.setName("meni"); // NOI18N

        datoteka.setText(resourceMap.getString("datoteka.text")); // NOI18N
        datoteka.setName("datoteka"); // NOI18N

        jMenuItem4.setText(resourceMap.getString("jMenuItem4.text")); // NOI18N
        jMenuItem4.setName("jMenuItem4"); // NOI18N
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem4ActionPerformed(evt);
            }
        });
        datoteka.add(jMenuItem4);

        jMenuItem5.setText(resourceMap.getString("jMenuItem5.text")); // NOI18N
        jMenuItem5.setName("jMenuItem5"); // NOI18N
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem5ActionPerformed(evt);
            }
        });
        datoteka.add(jMenuItem5);

        zapri.setText(resourceMap.getString("zapri.text")); // NOI18N
        zapri.setName("zapri"); // NOI18N
        zapri.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                zapriActionPerformed(evt);
            }
        });
        datoteka.add(zapri);

        meni.add(datoteka);

        jMenu1.setText(resourceMap.getString("jMenu1.text")); // NOI18N
        jMenu1.setName("jMenu1"); // NOI18N

        jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem2.setText(resourceMap.getString("jMenuItem2.text")); // NOI18N
        jMenuItem2.setName("jMenuItem2"); // NOI18N
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem2);

        jMenuItem3.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_V, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem3.setText(resourceMap.getString("jMenuItem3.text")); // NOI18N
        jMenuItem3.setName("jMenuItem3"); // NOI18N
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem3);

        jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_DELETE, 0));
        jMenuItem1.setText(resourceMap.getString("jMenuItem1.text")); // NOI18N
        jMenuItem1.setName("jMenuItem1"); // NOI18N
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        meni.add(jMenu1);

        okna.setText(resourceMap.getString("okna.text")); // NOI18N
        okna.setName("okna"); // NOI18N

        novoOkno.setText(resourceMap.getString("novoOkno.text")); // NOI18N
        novoOkno.setName("novoOkno"); // NOI18N
        novoOkno.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                novoOknoActionPerformed(evt);
            }
        });
        okna.add(novoOkno);

        zapriOkno.setText(resourceMap.getString("zapriOkno.text")); // NOI18N
        zapriOkno.setName("zapriOkno"); // NOI18N
        zapriOkno.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                zapriOknoActionPerformed(evt);
            }
        });
        okna.add(zapriOkno);

        separator.setName("separator"); // NOI18N
        okna.add(separator);

        meni.add(okna);

        setJMenuBar(meni);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(toolBar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 818, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(windowManager, javax.swing.GroupLayout.DEFAULT_SIZE, 593, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(toolBar, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(windowManager, javax.swing.GroupLayout.DEFAULT_SIZE, 349, Short.MAX_VALUE)))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
/**
 * close map editor
 * @param evt
 */
private void zapriActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_zapriActionPerformed
    setVisible(false);
    dispose();
}//GEN-LAST:event_zapriActionPerformed

/**
 * add new floor
 * @param evt
 */
private void novoOknoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_novoOknoActionPerformed
    addWindow(FLOOR_ASK);
}//GEN-LAST:event_novoOknoActionPerformed

/**
 * add new floor
 * @param evt
 */
private void newWindowActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newWindowActionPerformed
    addWindow(FLOOR_ASK);
}//GEN-LAST:event_newWindowActionPerformed

/**
 * change zoom
 * @param evt
 */
private void jSpinner1StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jSpinner1StateChanged
    for(int i=0;i<seznamArea.size();i++)
        seznamArea.get(i).setMetersPerPixel((Double)jSpinner1.getValue());
}//GEN-LAST:event_jSpinner1StateChanged

/** 
 * show choosen component in property editor
 * @param evt
 */
private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
    for(int i=0;i<seznamKomponent.size();i++)
        if(seznamKomponent.get(i).getName().equals(jComboBox1.getSelectedItem())){
            fillProperties(seznamKomponent.get(i));
            break;
        }
}//GEN-LAST:event_jComboBox1ActionPerformed

/**
 * delete selected components
 * @param evt
 */
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
   seznamArea.get(activeArea).removeSelectedComponent();
}//GEN-LAST:event_jMenuItem1ActionPerformed

/**
 * copy selected components
 * @param evt
 */
private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
   seznamArea.get(activeArea).copySelectedComponents();
}//GEN-LAST:event_jMenuItem2ActionPerformed

/**
 * paste components
 * @param evt
 */
private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
   seznamArea.get(activeArea).pasteCopiedComponents();
}//GEN-LAST:event_jMenuItem3ActionPerformed

/**
 * save map to a file
 * @param evt
 */
private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed
   controlObj.saveMapToFile(seznamArea);
}//GEN-LAST:event_jMenuItem4ActionPerformed

/**
 * delete floor selected by user
 */
private void deleteWindow(){
    //ce obstaja samo eno nadstropje, ga ne moremo izbrisati
    if(seznamOken.size()==1){
        JOptionPane.showMessageDialog(this, "You cannot delete the only floor!");
        return;
    }
    //kreiramo seznam vseh nadstropij
    Object[] possibilities = new Object[seznamArea.size()];
    int index=0;
    for(int i=mostLower;i<=mostUpper;i++){
        possibilities[index] = Integer.toString(i);
        index++;
    }
    String curFloor = Integer.toString(seznamArea.get(activeArea).getFloorNumber());
    //vprašamo uporabnika, katero nadstropje želi izbrisati
    String res = (String)JOptionPane.showInputDialog(this,"Which floor do you want delete?",
                    "Floor Delete",JOptionPane.PLAIN_MESSAGE,null,possibilities,curFloor);
    //če ne želi nobenega, gremo ven iz funkcije
    if(res==null) return;
    //poiščemo index izbranega nadstropja
    int choosen = Integer.parseInt(res);
    index = -1;
    for(int i=0;i<seznamArea.size();i++)
        if(seznamArea.get(i).getFloorNumber()==choosen){
            index = i;
            break;
        }
    //odstranimo iz vseh seznamov, ki se nanašajo na to nadstropje
    int delFloor = seznamArea.get(index).getFloorNumber();
    seznamArea.remove(index);
    seznamOken.get(index).dispose();
    seznamOken.remove(index);
    okna.remove(seznamMeni.get(index));
    seznamMeni.remove(index);
    //izberemo drugo aktivno okno
    if(activeArea>=seznamArea.size())
        activeArea = 0;
    //in ga aktiviramo
    try {
        seznamOken.get(activeArea).setSelected(true);
    } catch (PropertyVetoException ex) {
        ex.printStackTrace();
    }
    //popravimo še zaporedno številko nadstropja vsem ostalim
    if(delFloor>=0 && mostUpper>0){
        mostUpper--;
        for(int i=0;i<seznamArea.size();i++)
            if(seznamArea.get(i).getFloorNumber()>delFloor){
                seznamArea.get(i).setFloorNumber(seznamArea.get(i).getFloorNumber()-1);
                seznamOken.get(i).setTitle("Floor " + Integer.toString(seznamArea.get(i).getFloorNumber()));
                seznamMeni.get(i).setText(seznamOken.get(i).getTitle());
            }
    } else {
        mostLower++;
        for(int i=0;i<seznamArea.size();i++)
            if(seznamArea.get(i).getFloorNumber()<delFloor){
                seznamArea.get(i).setFloorNumber(seznamArea.get(i).getFloorNumber()+1);
                seznamOken.get(i).setTitle("Floor " + Integer.toString(seznamArea.get(i).getFloorNumber()));
                seznamMeni.get(i).setText(seznamOken.get(i).getTitle());
            }
    }
}


/**
 * analyze and create graph
 * @param evt
 */
private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed
   //prikažemo okno z sporočili
   SaveDialog saved = new SaveDialog();
   saved.setVisible(true);
   saved.showMessage("Analyzing...");
   //preverimo, če so vsa nadstropja pravilno narejena
   boolean isEntrance = false;
   for(int i=0;i<seznamArea.size();i++){
       Vector<MapComponent> items = seznamArea.get(i).getAllComponents();
       String passageType = "";
       boolean isExit = false;
       //za vsako komponento preverimo, da je pravilno povezana iz strani, iz katere je namenjena
       //in opozorimo, če ni
       for(int j=0;j<items.size();j++){
           MapComponent comp = items.get(j);
           if(comp instanceof Passage)
               passageType = (String)comp.getPropertyValue("Type");
           if(comp instanceof Entrance)
               isEntrance = true;
           if(comp instanceof Exit)
               isExit = true;
           boolean hasConnection = false;
           boolean hasJoint = false;
           Rectangle interRect = new Rectangle(0,0,-1,-1);
             interRect.setLocation(comp.getX()+comp.getWidth(),comp.getY());
             interRect.setSize(1,comp.getHeight());
             for(int k=0;k<items.size();k++)
                 if(items.get(k)!=comp && interRect.intersects(items.get(k).getBounds())){
                     hasConnection = true;
                     if(comp.jointSide(WorkArea.JOINT_RIGHT)&&!items.get(k).jointSide(WorkArea.JOINT_LEFT)){
                         saved.showMessage("Error: Element "+comp.getName()+" has not right neigbour element on the right side!\nFailed!");
                         saved.setButtonEnabled(true);
                         return;
                     } else
                         hasJoint = true;
                 }
             if(comp.jointSide(WorkArea.JOINT_RIGHT) && !hasJoint)
                 saved.showMessage("Warning: Element "+comp.getName()+" has not neigbour on the right side!");
             interRect.x = comp.getX()-1;
             hasJoint = false;
             for(int k=0;k<items.size();k++)
                 if(items.get(k)!=comp && interRect.intersects(items.get(k).getBounds())){
                     hasConnection = true;
                     if(comp.jointSide(WorkArea.JOINT_LEFT)&&!items.get(k).jointSide(WorkArea.JOINT_RIGHT)){
                         saved.showMessage("Error: Element "+comp.getName()+" has not right neigbour element on the left side!\nFailed!");
                         saved.setButtonEnabled(true);
                         return;
                     } else
                         hasJoint = true;
                 }
             if(comp.jointSide(WorkArea.JOINT_LEFT) && !hasJoint)
                 saved.showMessage("Warning: Element "+comp.getName()+" has not neigbour on the left side!");
             interRect.setLocation(comp.getX(),comp.getY()-1);
             interRect.setSize(comp.getWidth(),1);
             hasJoint = false;
             for(int k=0;k<items.size();k++)
                 if(items.get(k)!=comp && interRect.intersects(items.get(k).getBounds())){
                     hasConnection = true;
                     if(comp.jointSide(WorkArea.JOINT_TOP)&&!items.get(k).jointSide(WorkArea.JOINT_BOTTOM)){
                         saved.showMessage("Error: Element "+comp.getName()+" has not right neigbour element on the top!\nFailed!");
                         saved.setButtonEnabled(true);
                         return;
                     } else
                         hasJoint = true;
                 }
             if(comp.jointSide(WorkArea.JOINT_TOP) && !hasJoint)
                 saved.showMessage("Warning: Element "+comp.getName()+" has not neigbour on the top!");
             interRect.y = comp.getY()+comp.getHeight();
             hasJoint = false;
             for(int k=0;k<items.size();k++)
                 if(items.get(k)!=comp && interRect.intersects(items.get(k).getBounds())){
                     hasConnection = true;
                     if(comp.jointSide(WorkArea.JOINT_BOTTOM)&&!items.get(k).jointSide(WorkArea.JOINT_TOP)){
                         saved.showMessage("Error: Element "+comp.getName()+" has not right neigbour element at the bottom!\nFailed!");
                         saved.setButtonEnabled(true);
                         return;
                     } else
                         hasJoint = true;
                 }
             if(comp.jointSide(WorkArea.JOINT_BOTTOM) && !hasJoint)
                 saved.showMessage("Warning: Element "+comp.getName()+" has not neigbour at the bottom!");
           if(!hasConnection && !(comp instanceof Camera || comp instanceof Sensor)){
               saved.showMessage("Error: Found element without neighbour in floor "+seznamArea.get(i).getFloorNumber()+" \nFailed!");
               saved.setButtonEnabled(true);
               return;
           }
       }
       //v vsakem nadstropju mora biti prehod - če je več nadstropij
       if(passageType.equals("")&&seznamArea.size()>1){
           saved.showMessage("Error: No passage in floor "+seznamArea.get(i).getFloorNumber()+"\nFailed!");
           saved.setButtonEnabled(true);
           return;
       }
       //mora biti tudi izhod za ljudi
       if(!isExit){
           saved.showMessage("Error: No exit found!\nFailed!");
           saved.setButtonEnabled(true);
           return;
       }
   }
   //na celem parkirišču mora biti vsaj en vhod/izhod
   if(!isEntrance){
       saved.showMessage("Error: No car entrance found!\nFailed!");
       saved.setButtonEnabled(true);
       return;
   }
   //ko smo preverili, generiramo graf
   SimpleWeightedGraph<MapComponent,RoadEdge> graf = new SimpleWeightedGraph<MapComponent,RoadEdge>(RoadEdge.class);
   int secName = -1;
   //najprej ovinkom in križiščem določimo, ali je nanje vezan vhod/izhod
   for(int j=mostLower;j<=mostUpper;j++){
       Vector<RoadData> data = getFloor(j).getRoadlist();
       Vector<MapComponent> flItems = getFloor(j).getAllComponents();
       for(int i=0;i<flItems.size();i++)
           flItems.get(i).setEntryVertex(false);
       for(int i=0;i<flItems.size();i++){
           flItems.get(i).setEntryVertex(false);
           if(flItems.get(i) instanceof Entrance){
               Rectangle inter = new Rectangle();
               Entrance enter = (Entrance) flItems.get(i);
               inter.setBounds(enter.getBounds());
               int side  = 0;
               if(enter.jointSide(WorkArea.JOINT_BOTTOM)){
                   inter.height = 1;
                   inter.y += enter.getHeight();
                   side = WorkArea.JOINT_TOP;
               }
               if(enter.jointSide(WorkArea.JOINT_TOP)){
                   inter.height = 1;
                   inter.y -= 1;
                   side = WorkArea.JOINT_BOTTOM;
               }
               if(enter.jointSide(WorkArea.JOINT_RIGHT)){
                   inter.width = 1;
                   inter.x += enter.getWidth();
                   side = WorkArea.JOINT_LEFT;
               }
               if(enter.jointSide(WorkArea.JOINT_LEFT)){
                   inter.width = 1;
                   inter.x -= 1;
                   side = WorkArea.JOINT_RIGHT;
               }
               for(int k=0;k<flItems.size();k++){
                   MapComponent temp = flItems.get(k);
                   if((temp instanceof Turn || temp instanceof CrossRoad)
                      && temp.getBounds().intersects(inter) && temp.jointSide(side)){
                       temp.setEntryVertex(true);
                   }
               }
           }
       }
       //dodamo vse povezave in krajišča        
       for(int i=0;i<data.size();i++){
               RoadData item = data.get(i);
               if(item.start != null && item.end!= null){
                   if(!graf.containsVertex(item.start)){
                       
                       graf.addVertex(item.start);
                   }
                   if(!graf.containsVertex(item.end)){
                       graf.addVertex(item.end);
                   }
                   RoadEdge edge = graf.addEdge(item.start,item.end);
                   edge.setNumParkBoxes(item.numParkLot);
                   secName++;
                   edge.setNumParkBoxes(item.numParkLot);
                   edge.setSection(Integer.toString(secName));
                   edge.setDistanceExit(item.distanceExit);
                   edge.setExitName(item.exitName);
                   graf.setEdgeWeight(edge, item.length);
               } else
                   saved.showMessage("povezava ni dodana, ker nima na koncih ovinka ali krizisca!");
       }
   }
   //če je več nadstropij, pa dodamo še povezave med njimi
   if(seznamArea.size()>1){
       for(int j=mostLower;j<mostUpper;j++){
           Vector<MapComponent> cItem = getFloor(j).getAllComponents();
           Passage cPassage = null;
           MapComponent cStart = null;
           MapComponent cEnd = null;
           for(int i=0;i<cItem.size();i++)
               if(cItem.get(i) instanceof Passage){
                   cPassage = (Passage) cItem.get(i);
               }
           String typePassage = (String) cPassage.getPropertyValue("Type");
           if(typePassage.contains("Vertical")){
               Rectangle top = new Rectangle(cPassage.getWidth(), 1);
               top.setLocation(cPassage.getX(), cPassage.getY()-1);
               Rectangle bottom = new Rectangle(cPassage.getWidth(), 1);
               bottom.setLocation(cPassage.getX(), cPassage.getY()+cPassage.getHeight());
               for(int i=0;i<cItem.size();i++)
                     if(cItem.get(i) instanceof CrossRoad || cItem.get(i) instanceof Turn){
                        if(cItem.get(i).getBounds().intersects(top) && cItem.get(i).jointSide(WorkArea.JOINT_BOTTOM))
                            cEnd = cItem.get(i);
                        if(cItem.get(i).getBounds().intersects(bottom)  && cItem.get(i).jointSide(WorkArea.JOINT_TOP))
                            cStart = cItem.get(i);
                     }
           } else {
               Rectangle left = new Rectangle(1,cPassage.getHeight());
               left.setLocation(cPassage.getX()-1, cPassage.getY());
               Rectangle right = new Rectangle(1,cPassage.getHeight());
               right.setLocation(cPassage.getX()+cPassage.getWidth(), cPassage.getY());
               for(int i=0;i<cItem.size();i++)
                     if(cItem.get(i) instanceof CrossRoad || cItem.get(i) instanceof Turn){
                        if(cItem.get(i).getBounds().intersects(left) && cItem.get(i).jointSide(WorkArea.JOINT_BOTTOM))
                            cEnd = cItem.get(i);
                        if(cItem.get(i).getBounds().intersects(right)  && cItem.get(i).jointSide(WorkArea.JOINT_TOP))
                            cStart = cItem.get(i);
                     }
           }
           Vector<MapComponent> uItem = getFloor(j+1).getAllComponents();
           Passage uPassage = null;
           MapComponent uStart = null;
           MapComponent uEnd = null;
           for(int i=0;i<uItem.size();i++)
               if(uItem.get(i) instanceof Passage){
                   uPassage = (Passage) uItem.get(i);
               }
           typePassage = (String) uPassage.getPropertyValue("Type");
           if(typePassage.contains("Vertical")){
               Rectangle top = new Rectangle(uPassage.getWidth(), 1);
               top.setLocation(uPassage.getX(), uPassage.getY()-1);
               Rectangle bottom = new Rectangle(uPassage.getWidth(), 1);
               bottom.setLocation(uPassage.getX(), uPassage.getY()+uPassage.getHeight());
               for(int i=0;i<uItem.size();i++)
                     if(uItem.get(i) instanceof CrossRoad || uItem.get(i) instanceof Turn){
                        if(uItem.get(i).getBounds().intersects(top) && uItem.get(i).jointSide(WorkArea.JOINT_BOTTOM))
                            uEnd = uItem.get(i);
                        if(uItem.get(i).getBounds().intersects(bottom)  && uItem.get(i).jointSide(WorkArea.JOINT_TOP))
                            uStart = uItem.get(i);
                     }
           } else {
               Rectangle left = new Rectangle(1,uPassage.getHeight());
               left.setLocation(uPassage.getX()-1, uPassage.getY());
               Rectangle right = new Rectangle(1,uPassage.getHeight());
               right.setLocation(uPassage.getX()+uPassage.getWidth(), uPassage.getY());
               for(int i=0;i<uItem.size();i++)
                     if(uItem.get(i) instanceof CrossRoad || uItem.get(i) instanceof Turn){
                        if(uItem.get(i).getBounds().intersects(left) && uItem.get(i).jointSide(WorkArea.JOINT_BOTTOM))
                            uEnd = uItem.get(i);
                        if(uItem.get(i).getBounds().intersects(right)  && uItem.get(i).jointSide(WorkArea.JOINT_TOP))
                            uStart = uItem.get(i);
                     }
           }
           if(cStart == null || cEnd == null || uStart == null || uEnd == null){
               saved.showMessage("Error: Passage can be connected only with Turns or Crossroads!\nFailed!");
               saved.setButtonEnabled(true);
               return;
           }
           RoadEdge edge = graf.addEdge(cStart,uEnd);
           edge.setNumParkBoxes(0);
           secName++;
           edge.setSection(Integer.toString(secName));
           edge.setDistanceExit(-1);
           graf.setEdgeWeight(edge, 10);
           edge = graf.addEdge(uStart,cEnd);
           edge.setNumParkBoxes(0);
           secName++;
           edge.setSection(Integer.toString(secName));
           edge.setDistanceExit(-1);
           graf.setEdgeWeight(edge, 10);
       }
   }
   //nato shranimo graf
   if(!controlObj.saveGraph(graf)){
       saved.showMessage("Graph can NOT be saved!\nFailed!");
       return;  
   }
   saved.showMessage("Graph created...");
   saved.setButtonEnabled(true);
}//GEN-LAST:event_jMenuItem5ActionPerformed

/**
 * delete floor
 * @param evt
 */
private void zapriOknoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_zapriOknoActionPerformed
    deleteWindow();
}//GEN-LAST:event_zapriOknoActionPerformed

/**
 * delete floor
 * @param evt
 */
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    deleteWindow();
}//GEN-LAST:event_jButton1ActionPerformed

/**
 * get floor with specific number
 * @param floorNum
 * @return
 */
private WorkArea getFloor(int floorNum){
    for(int i=0;i<seznamArea.size();i++)
       if(seznamArea.get(i).getFloorNumber()==floorNum)
           return seznamArea.get(i);
    return null;
}
      
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenu datoteka;
    private javax.swing.JButton jButton1;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSpinner jSpinner1;
    private javax.swing.JTable jTable1;
    private javax.swing.JMenuBar meni;
    private javax.swing.JButton newWindow;
    private javax.swing.JMenuItem novoOkno;
    private javax.swing.JMenu okna;
    private javax.swing.JSeparator separator;
    private javax.swing.JToolBar toolBar;
    private javax.swing.JDesktopPane windowManager;
    private javax.swing.JMenuItem zapri;
    private javax.swing.JMenuItem zapriOkno;
    // End of variables declaration//GEN-END:variables
    
}
